/// IMAGES UPLOADERS
function get_rte_object(){

}
function image_insert(imagePath){
  try{
    var rte =window.opener.insert_image_into;
    var oRTE=window.opener.document.getElementById(rte);
    if (window.opener.document.all) {
      oRTE = window.opener.frames[rte];
      //get current selected range
      var selection = oRTE.document.selection; 
      if (selection != null) {rng = selection.createRange();}
    }else{
      oRTE = window.opener.document.getElementById(rte).contentWindow;
      //get currently selected range
      var selection = oRTE.getSelection();
      rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    }
    if((imagePath != null) && (imagePath != "")) {
      oRTE.focus();
      oRTE.document.execCommand('InsertImage', false, imagePath);
      oRTE.focus();
    }
  }catch(e){
    logging("Error image_insert:"+e.message);
  }
}

function image_copy(path){    
  logging(path);
}

var editor_id="";

function AddImage(rte,entity,id) {
  try{
    window.insert_image_into=rte;
    wnd=pop_up('/object.images/'+entity+'/'+id,'750','600');
    return false;
  }catch(e){
    logging("Error AddImage:"+e.message);
  }
}

function file_insert(path){
  try{
    alert(path);
  }catch(e){
    logging("Error file_insert:"+e.message);
  }
}

function image_delete(object,id){
  try{
    var url=getHost()+"object.image_delete/"+id;
    aGet(url);
    var image_container=object.parentNode.parentNode;
    var images_container=object.parentNode.parentNode.parentNode;
    images_container.removeChild(image_container);
  }catch(e){
    logging("Error file_insert:"+e.message);
  }
}

function image_deleted(){
  try{

  }catch(e){
    alert("Error in image_deleted:"+e.message);
  }
}


function insert_element(kind,path,id){
  try{
    var rteID=window.opener.insert_image_into;
    var oRTE=window.opener.document.getElementById(rteID).contentWindow;
    switch(kind){
      case "image"     : {oRTE.document.execCommand('InsertImage', false, "/"+path);break;}
      case "link"      : {pasteHtml(oRTE,"{file kind=\"link\" id=\""+id+"\" name=\""+path+"\" }");break;}
      case "download"  : {var desc=prompt("Enter file description:", "");pasteHtml(oRTE,"{file kind=\"download\" id=\""+id+"\" name=\""+desc+"\" }");break;}
      case "video"     : {pasteHtml(oRTE,"{file kind=\"video\" id=\""+id+"\" name=\""+path+"\" }");break;}
      case "flash"     : {pasteHtml(oRTE,"{file kind=\"flash\" id=\""+id+"\" name=\""+path+"\" }");break;}
      case "icon"      : {pasteHtml(oRTE,"{file kind=\"icon\" id=\""+id+"\" name=\""+path+"\" }");break;}
    }
    return false;
  }catch(e){
    alert("Error insert_element:"+e.message);
  }
}
